package com.demoo.zjsu.service.smartwebsite.zjgsu;

import com.demoo.zjsu.model.smartwebsite.PageTwo;
import com.demoo.zjsu.model.smartwebsite.PageTwoContent;
import com.demoo.zjsu.service.smartwebsite.Page;
import com.demoo.zjsu.service.smartwebsite.PageFactory;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

/**
 * Created by jshjsh on 2016/8/17.
 * 常用信息http://www.hzic.edu.cn/Channel_32/
 * 信息服务
 */
@Service
public class PhonePageService extends PageFactory{



    @Override
    public Elements getOtherMain(Document document) {
        return document.select("[width=100%]").eq(1);
    }

    @Override
    public PageTwo dealTitle(String url, String title) {

        return new PageTwo(title, "", url.replace(".html", ""), 0);
    }

    @Override
    public void filterAgain(Elements elements) {
        elements.select("tr").eq(0).remove();
        elements.select("p:contains(28877268)").remove();
        Elements elements1 = elements.select("p:matches(.*[0-9]{4,}.*[0-9]{4,}+)");
        Elements elements2 = elements.select("p:matches(w+.*.cn)");
        for (Element element : elements1) {
            String src = element.text().replaceAll("[^0-9^/^-]", "");
            element.wrap("<a href='tel://"+src+"'></a>");
        }

        for (Element element : elements2) {
            String href = "http://"+element.text().replaceAll("[^\\.0-9a-zA-Z]","");
            element.wrap("<a href='" + href + "'></a>");
        }
    }

    @Override
    public PageTwoContent getContent(Elements elements) {
        return getPageTwoContent(elements);
    }



    @Override
    public Page getPage() {
        return new Page("http://www.hzic.edu.cn/Channel_32/", "信息服务");
    }

    @Override
    public Elements getMain(Document document) {
        return document.select("[height=400]");
    }


}
